// const api_root = 'https://www.bast-seller.com/api' //pt http://154.85.43.101:8785/710b7e1f/
// const api_root = 'https://www.indian-amazon.com/api'  //en http://154.85.58.158:8888/710b7e1f/
const api_root = 'https://www.hit-sale.com/api'  //en http://154.85.45.61:8785/710b7e1f/
const api = {
	root:api_root,
	app_paycreate: api_root+'/app_paycreate',
	app_image:api_root+'/app_image',
	app_index:api_root+'/app_index',
	app_register:api_root+'/app_register',
	app_login:api_root+'/app_login',
	app_getfinancial:api_root+'/app_getfinancial',
	app_setfinancial:api_root+'/app_setfinancial',
	app_myfinancial:api_root+'/app_myfinancial',
	app_outfinancial:api_root+'/app_outfinancial',
	app_getinfo:api_root+'/app_getinfo',
	app_start:api_root+'/app_start',
	app_settlement:api_root+'/app_settlement',
	app_mylist:api_root+'/app_mylist',
	app_myuser:api_root+'/app_myuser',
	app_mydetail:api_root+'/app_mydetail',
	app_getpay:api_root+'/app_getpay',
	app_setpay:api_root+'/app_setpay',
	app_getbank:api_root+'/app_getbank',
	app_withdrawal:api_root+'/app_withdrawal',
	app_bindbank:api_root+'/app_bindbank',
	app_withdrawal_list:api_root+'/app_withdrawal_list',
	app_setpay_list:api_root+'/app_setpay_list',
	app_updatepass:api_root+'/app_updatepass',
	app_updatejypass:api_root+'/app_updatejypass',
	app_getagency:api_root+'/app_getagency',
	app_agencyall:api_root+'/app_agencyall',
	app_agencydetail:api_root+'/app_agencydetail',
	app_getkefu:api_root+'/app_getkefu',
	app_getcode:api_root+'/app_getcode',
	app_getlevel:api_root+'/app_getlevel',
	app_setlevel:api_root+'/app_setlevel'
}
const upload = function(self,url,data,type,path,name,_success){
	if(path==''){
		uni.request({
			url:url,
			method:type,
			data:data,
			header:{
				'authorization':uni.getStorageSync('token')
			},
			success:res=>{
				_success(self,res.resBody)
			}
		})
	}else{
		uni.uploadFile({
			url:url,
			filePath:path,
			name:name,
			formData:data,
			header:{
				'authorization':uni.getStorageSync('token')
			},
			success:res=>{
				var data = JSON.parse(res.data)
				if(data.resCode==0){
					_success(self,data.resBody)
				}else{
					uni.showToast({
						icon:'none',
						title:self.$t('service.'+data.resMsg)
					})
					setTimeout(function(){
						uni.hideLoading()
					},3000)
				}
			}
		})
	}
}

const normal = function(self,url,data,_success){
	uni.request({
		url:url,
		method:"POST",
		data:data,
		header:{
			'authorization':uni.getStorageSync('token')
		},
		success:res=>{
			if(res.data.resCode==0){
				_success(self,res.data.resBody)
			}else{
				console.log(self.$t('service.parameters'))
				uni.showToast({
					icon:'none',
					title:self.$t('service.'+res.data.resMsg)
				})
				setTimeout(function(){
					uni.hideLoading()
				},3000)
			}
		}
	})
}

const auth = function(self,url,data,_success){
	if(uni.getStorageSync('token')==''){
		setTimeout(function(){
			uni.reLaunch({
				url:'/pages/login/login'
			})
		},1000);
		return;
	}
	uni.request({
		url:url,
		method:"POST",
		data:data,
		header:{
			'authorization':uni.getStorageSync('token')
		},
		success:res=>{
			if(res.data.resCode==0){
				_success(self,res.data.resBody)
			}else{
				uni.showToast({
					icon:'none',
					title:self.$t('service.'+res.data.resMsg)
				})
				setTimeout(function(){
					uni.hideLoading()
				},3000)
			}
		}
	})
}

export default{
	api,
	auth,
	upload,
	normal
}